<?php defined('IN_ADMIN') or exit('No permission resources.');?>
<?php include $this->admin_tpl('header', 'admin');?>
<script type="text/javascript" src="<?php echo JS_PATH?>jquery.sgallery.js"></script>
<div class="subnav">
	<?php if($_GET['bindtype'] == 1):?>
	<h2 class="title-1 line-x f14 fb blue lh28"><?php echo L('motolist');?>--<?php echo $data['username'];?>--<?php echo L('resource_list');?></h2>
	<?php endif;?>
	<div class="content-menu ib-a blue">
		<a class="add fb" href="javascript:void(0)"><em><?php echo L('resource_manage');?></em></a>
		<span>|</span>
		<a href="?m=resource&c=manage&a=add&relevance_id=<?php echo $data['id'];?>&bindtype=<?php echo $_GET['bindtype']?>" ><em><?php echo L('resource_add');?></em></a>
	</div>
</div>
<div class="pad-lr-10">

<form name="myform" action="" method="post">
<div class="table-list">
<table width="100%" cellspacing="0">
	<thead>
		<tr>
			<th  align="left" width="20"><input type="checkbox" value="" id="check_box" onclick="selectall('id[]');"></th>
			<th align="left">ID</th>
			<th align="left"><?php echo L('name')?></th>
			<th align="left"><?php echo L('uploadtime')?></th>
			<th align="left"><?php echo L('content')?></th>
			<th align="left"><?php echo L('type')?></th>
			<th align="left"><?php echo L('operation')?></th>
		</tr>
	</thead>
<tbody>
<?php
	foreach($resourcelist as $k=>$v) {
?>
    <tr>
		<td align="left"><input type="checkbox" value="<?php echo $v['id']?>" name="id[]"></td>
		<td align="left"><?php echo $v['id']?></td>
		<td align="left"><?php echo $v['title']?></td>
		<td align="left"><?php echo format::date($v['addtime'], 1)?></td>
		<td align="left"><?php echo $v['content']?></td>
		<td align="left">
			<?php if($v['resource_type'] == 1){echo '图片';}elseif($v['resource_type'] == 2){echo '视频';}elseif ($v['resource_type'] == 3){echo '其他';}?>
		</td>
		<td align="left">
		<a href="javascript:preview(<?php echo $v['id']?>, '<?php echo $v['content']?>','<?php echo $v['content']?>')">[<?php echo L('preview')?>]</a>
		<a href="?m=resource&c=manage&a=edit&resourceid=<?php echo $v['id']?>&relevance_id=<?php echo $data['id']?>&bindtype=<?php echo $_GET['bindtype']?>">[<?php echo L('edit')?>]</a>
		<a href="?m=resource&c=manage&a=delete&id=<?php echo $v['id']?>" onClick="return confirm('<?php echo L('confirm')?>')">[<?php echo L('del')?>]</a>
		
		 </td>
    </tr>
<?php
	}

?>
</tbody>
</table>

<div class="btn">
<label for="check_box"><a href="#" onClick="javascript:$('input[type=checkbox]').attr('checked', true)"><?php echo L('select_all')?></a>/<a href="#" onClick="javascript:$('input[type=checkbox]').attr('checked', false)"><?php echo L('cancel')?></a></label> <input type="submit" class="button" name="dosubmit" value="<?php echo L('delete')?>"onClick="checkid();"/>
</div>

<div id="pages"><?php echo $pages?></div>
</div>
</form>
</div>
<script type="text/javascript">
<!--
function preview(id, name,filepath) {
	if(IsImg(filepath)) {
		window.top.art.dialog({title:'<?php echo L('preview')?>',fixed:true, content:'<img src="'+filepath+'" onload="$(this).LoadImage(true, 500, 500,\'<?php echo IMG_PATH?>s_nopic.gif\');"/>'});	
	} else {
		window.top.art.dialog({title:'<?php echo L('preview')?>',fixed:true, content:'<a href="'+filepath+'" target="_blank"><img src="<?php echo IMG_PATH?>admin_img/down.gif"><?php echo L('click_open')?></a>'});
	}
};
function IsImg(url){
	  var sTemp;
	  var b=false;
	  var opt="jpg|gif|png|bmp|jpeg";
	  var s=opt.toUpperCase().split("|");
	  for (var i=0;i<s.length ;i++ ){
	    sTemp=url.substr(url.length-s[i].length-1);
	    sTemp=sTemp.toUpperCase();
	    s[i]="."+s[i];
	    if (s[i]==sTemp){
	      b=true;
	      break;
	    }
	  }
	  return b;
};
function checkid() {
	var ids='';
	$("input[name='id[]']:checked").each(function(i, n){
		ids += $(n).val() + ',';
	});
	if(ids=='') {
		window.top.art.dialog({content:'<?php echo L('plsease_select')?>',lock:true,width:'200',height:'50',time:1.5},function(){});
		return false;
	} else {
		if(window.confirm("确定删除所选记录？")){
            $.ajax({
                type : "post",  
                url : "?m=resource&c=manage&a=del_all&pc_hash=<?php echo $_SESSION['pc_hash'];?>", //要自行删除的action  
                dataType : 'json', 
                data : {id:ids,bindtype:<?php echo $_GET['bindtype']?>}, 
                success : function(data) {
                    if(data == 1){
                        alert("删除成功");
                    }else{
                        alert('删除失败');
                    }
                },  
                error : function(data) {
                    alert("您没有权限操作该项");  
                }  
            });  
        }  
	}
}

window.top.$('#display_center_id').css('display','none');
//-->
</script>
</body>
</html>